package com.fancy.learncenter.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.LinearLayout;

import com.facebook.drawee.view.SimpleDraweeView;
import com.fancy.learncenter.R;
import com.fancy.learncenter.bean.AddDiscussDataBean;
import com.fancy.learncenter.bean.BookStoreDataBean;
import com.fancy.learncenter.ui.activity.LargeImageActivity;
import com.fancy.learncenter.ui.adapter.base.CommonRecycleViewAdapter;
import com.fancy.learncenter.ui.adapter.base.CustomViewHold;
import com.fancy.learncenter.ui.callback.AlbumImpl;
import com.fancy.learncenter.utils.ImgFilter;
import com.fancy.learncenter.utils.Utils;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2017/4/19.
 */

public class Album4Adapter extends CommonRecycleViewAdapter<String> {
    Context mContext;
    AlbumImpl listener;
    List<String> itemDatasFull;

    public void setShow4(boolean show4) {
        isShow4 = show4;
    }

    boolean isShow4;



    public Album4Adapter(Context mContext, boolean isShow4,List<String> itemDatasFull,  List<String> itemDatas,AlbumImpl listener) {
        super(mContext, R.layout.gold_lecture_album_item, itemDatas);
        this.mContext = mContext;
        this.listener = listener;
        this.isShow4 = isShow4;
        this.itemDatasFull = itemDatasFull;
    }

    @Override
    public void bindView(CustomViewHold customViewHold, String item, final int position) {

        final SimpleDraweeView albumView = customViewHold.getView(R.id.album_item);
        LinearLayout maskedLayout = customViewHold.getView(R.id.masked_layout);

        albumView.setImageURI(Utils.getImgUri(item+ ImgFilter.SSCC_H200));

        FrameLayout.LayoutParams flp = (FrameLayout.LayoutParams) maskedLayout.getLayoutParams();
        FrameLayout.LayoutParams slp = (FrameLayout.LayoutParams) albumView.getLayoutParams();
        int width = (Utils.getScreeWidth() - 40 * 2 - 10 * 3) / 4;
        flp.width = width;
        flp.height = width;
        slp.width = width;
        slp.height = width;
        maskedLayout.setLayoutParams(flp);
        albumView.setLayoutParams(slp);
        if (position == 3 && isShow4) {
            maskedLayout.setVisibility(View.VISIBLE);
        } else {
            maskedLayout.setVisibility(View.GONE);
        }

        final ArrayList<String> arrayList = new ArrayList<>();
        arrayList.addAll(itemDatasFull);

        customViewHold.getRoorView().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (position == 3 && isShow4  && listener != null) {
                    listener.onClick(position);
                } else {
                    Intent intent = new Intent(mContext, LargeImageActivity.class);
                    intent.putStringArrayListExtra("list", arrayList);
                    intent.putExtra("position", position);
                    mContext.startActivity(intent);
                }
            }
        });


    }
}
